package com.zzyl.controller;


import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/nursing/plan")
@Api(tags = "护理计划管理")
public class NursingPlanController extends BaseController{
    @Autowired
    private NursingPlanService nursingPlanService;



    /**
     * 获取所有护理计划
     * @return
     */
    @ApiOperation("查询所有护理计划")
    @GetMapping
    public ResponseResult getAll(){
        return ResponseResult.success(nursingPlanService.getAll());
    }



    /**
     * 条件分页查询
     * @param name 护理计划名称
     * @param pageNum  页码
     * @param pageSize 每页大小
     * @param status  护理计划状态
     * @return
     */
    @GetMapping("/search")

    public ResponseResult selectPlanByPage(String name,Integer pageNum,Integer pageSize,Integer status){
        return ResponseResult.success(nursingPlanService.selectPlanByPage(name, pageNum, pageSize, status));


    }




    /**
     * 新增护理计划
     * @param nursingPlanDto
     * @return
     */
    @ApiOperation("添加护理计划")
    @PostMapping
  public ResponseResult addPlan(@RequestBody  NursingPlanDto nursingPlanDto){
        nursingPlanService.addPlan(nursingPlanDto);
        return ResponseResult.success();
    }

    /**
     * 删除护理计划
     * @param id 护理计划id
     * @return
     */
    @ApiOperation("删除护理计划")
    @DeleteMapping("/{id}")
    public ResponseResult deletePlanById(@PathVariable Long id){
        nursingPlanService.removeById(id);
           return ResponseResult.success();
    }


    /**
     * 根据id获取护理计划详情
     * @param id 护理计划id
     * @return
     */
    @ApiOperation("根据ID查询护理计划")
    @GetMapping("/{id}")
    public ResponseResult getPlanById(@PathVariable Long id){
        return ResponseResult.success(nursingPlanService.getById(id));
    }


    /**
     * 修改护理计划
     * @param nursingPlanDto
     * @return
     */
    @ApiOperation("修改护理计划")
    @PutMapping("/{id}")
    public ResponseResult updatePlan(@RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.updatePlanById(nursingPlanDto);

        return ResponseResult.success();
    }

    /**
     * 启用，禁用
     * @param id 护理计划id
     * @param status 护理计划状态
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    public ResponseResult updateStatus(@PathVariable Long id,@PathVariable Integer status){

        return toAjax(  nursingPlanService.updateStatus(id,status) );
    }














}
